<?php

namespace plugin\coupon\app\admin\controller;

use app\common\controller\BaseAdminController;
use plugin\coupon\app\admin\logic\CouponReceiveLogLogic;
use think\db\Query;

/**
 * 卡券领取记录
 * Class CouponReceiveLogController
 * @package plugin\coupon\app\admin\controller
 */
class CouponReceiveLogController extends BaseAdminController
{
    protected function init()
    {
        parent::init();
        $this->logic = new CouponReceiveLogLogic();
    }

    protected function searchWhere()
    {
        $where = [];

        return $where;
    }

    public function list()
    {
        $where = [];
        $this->form['name'] && $where[] = ['coupon_name', 'like', "%{$this->form['name']}%"];
        $query = $this->logic->search($where);
        $query->order($this->listOrder());
        $query->field($this->field ?: '*');
        $query->with([
            'coupon',
            'user' => function (Query $query) {
                $query->field([
                    'id',
                    'nickname',
                ]);
            },
        ]);
        $data = $this->logic->getPageList($query);
        return $this->success($data);
    }

}
